﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using webapp4U;
using webapp4U.BOL;

public partial class UserControl_ControlInDieuChinhTonKho : System.Web.UI.UserControl
{
    ClassExecute.ClassExecute dt;
    string str = webapp4U.Configuration.CurrentConnectionString;
    string error = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataBind();
        }
        if (ViewState["strSoHoaDon"] != null)
        {
            ControlReportViewer1.ReportViewer.Report = CreateReport(ViewState["strSoHoaDon"].ToString());
        }

    }
    public override void DataBind()
    {
        if (Session["Sitecode"] != null)
        {
            dt = new ClassExecute.ClassExecute();
            DataTable db = dt.Get_Data_DataTable(str, ref error, "ls_getAdjTrnList", CommandType.StoredProcedure, new SqlParameter("@siteCode", Session["Sitecode"].ToString()));
            if (db.Rows.Count > 0)
            {
                grdvNghiepVuNhanHangLists.DataSource = db;
                grdvNghiepVuNhanHangLists.DataBind();
            }
        }
    }

   
    protected void grdvNghiepVuNhanHangLists_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (Session["Sitecode"] != null)
        {
            string strSoHoaDon = grdvNghiepVuNhanHangLists.SelectedDataKey.Value.ToString();
            dt = new ClassExecute.ClassExecute();
            dt.ExecuteSQl_bool(str, CommandType.StoredProcedure, "TTr_UpdateAdjTrnPrinted", ref error,
                new SqlParameter("@docno", strSoHoaDon), new SqlParameter("@siteCode", Session["Sitecode"].ToString()));
            ViewState["strSoHoaDon"] = strSoHoaDon;
            ControlReportViewer1.ReportViewer.Report = CreateReport(strSoHoaDon);
            DataBind();
            UpdatePanel1.Update();
            TabContainer1.ActiveTabIndex = 1; 
            //string url = "~/Pages/InDieuChinhTonKho/Printing.aspx?DocNo=" + strSoHoaDon;
            //webapp4U.ResponseHelper.Redirect(this.Response, url, "_blank", "menubar=0,width=900,height=700");
            //Response.Redirect(url);

        }
    }
    DevExpress.XtraReports.UI.XtraReport CreateReport(string strSoHoaDon)
    {
        XtraReportInDieuChinhKho tableReport = new XtraReportInDieuChinhKho();
        if (Session["Sitecode"] != null)
        {
            string DocNo = strSoHoaDon;
            //if (Request.QueryString["DocNo"] != null)
            //{
            //    DocNo = Request.QueryString["DocNo"].ToString();
            //}
            dt = new ClassExecute.ClassExecute();
            DataSet ds = new DataSet();

            ds = dt.Get_Data_DataSet(str, ref error, "k_getAdjTrnDetail4Print", CommandType.StoredProcedure,
                new SqlParameter("@docNo", DocNo),
                new SqlParameter("@siteCode", Session["Sitecode"].ToString()));

            tableReport.SetReportParameter(ds);
        }
        return tableReport;
    }

    protected void grdvNghiepVuNhanHangLists_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdvNghiepVuNhanHangLists.PageIndex = e.NewPageIndex;
        DataBind();
    }
   
    protected void imgBtnAdd_Click(object sender, ImageClickEventArgs e)
    {
        DataBind();
    }
}